package com.example.service.impl;

import com.example.context.BaseContext;
import com.example.entity.User;
import com.example.entity.UserInfo;
import com.example.mapper.UserMapper;
import com.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;
    @Override
    public User findUserByName(String username) {
        return userMapper.findUserByName(username);
    }

    @Override
    public void register(String username, String password) {
        userMapper.addUser(username,password);
    }

    @Override
    public UserInfo getUserInfo() {
        Long id = BaseContext.getCurrentId();
       User user= userMapper.findById(id);
       UserInfo userInfo= UserInfo.builder()
               .isUpdatedPassword(false)
               .portrait(user.getPortrait())
               .userName(user.getUserName())
               .build();
       return userInfo;
    }
}
